package com.zl.learning.thread;

public class SimpleWN {
    private final static Object object = new Object();

    public static class T1 extends Thread {
        public T1(String name){
            this.setName(name);
        }
        @Override
        public void run() {
            synchronized (object) {
                try {
                    System.out.println(System.currentTimeMillis() + ":T1 start!");
                    object.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(System.currentTimeMillis()+":T1 end!");
            }
        }
    }

    public static class T2 extends Thread{
        public T2(String name){
            this.setName(name);
        }
        @Override
        public void run() {
            synchronized (object){
                System.out.println(System.currentTimeMillis()+":T2 start! notify on thread");
                object.notifyAll();
                System.out.println(System.currentTimeMillis()+":T2 end!");
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new T1("t1");
        Thread t2 = new T2("t2");
        t1.start();
        Thread.sleep(100);
        t2.start();
    }
}
